import Toast from './Toast.vue'
import Vue from 'vue'

function MessageShow(option) {
  if (option && ['success', 'error'].includes(option.type)) {
    MessageShow[option.type](option)
  }
}

MessageShow.init = () => {
  const Message = Vue.extend(Toast)
  const MessageExtend = new Message({
    el: document.createElement('div')
  })

  return MessageExtend
}
MessageShow.error = function (option) {
  const MessageExtend = MessageShow.init()
  document.body.appendChild(MessageExtend.$el)
  MessageExtend.error(option)
}
MessageShow.success = function (option) {
  const MessageExtend = MessageShow.init()
  document.body.appendChild(MessageExtend.$el)
  MessageExtend.success(option)
}

export default {
  install(Vue) {
    Vue.prototype.$message = MessageShow
  }
}
